<?if(isset($print)):?>
<style>
	table{
		width: 100%;
	}
	table.table{
		border: 1px solid #000;
		border-collapse: collapse;
	}
	table.table tr td{
		border: 1px solid #000;
		padding:2px 5px;
		font-size:12px;
	}
	a{
		color:#000;
		text-decoration:none;
	}
</style>
<table>
	<tr>
		<td style="font-size:20; text-align:center;font-weight:bold;"><?=@$school_name;?></td>
	</tr>
	<tr>
		<td style="font-size:12px; text-align:center;font-weight:bold;">Section Overview</td>
	</tr>
	<tr>
		<td style="font-size:12px; text-align:center;font-weight:bold;">School Year: <?=@$school_year;?></td>
	</tr>
	<tr>
		<td style="font-size:12px; text-align:center;font-weight:bold;"><?=@$print_title;?></td>
	</tr>
</table>
<?endif;?>
<h5>Section Summary</h5>
<?if($summary):
	$male= [];
	$female = [];
?>
	<table class="table">
			<tr class="success">
				<td>&nbsp;</td>
				<td><strong>MALE</strong></td>
				<td><strong>FEMALE</strong></td>
				<td><strong>TOTAL</strong></td>
			</tr>
		<?foreach ($summary as $sk => $sv):?>
			<tr class="info">
				<td colspan="4" style="text-align:center;font-weight:bold;"><?=ucwords(strtolower($sv['level']))?></td>
			</tr>
			<?	//with blocks
				if($sv['block_stat']):?>
				<?foreach ($sv['block_data'] as $wbk => $wbv):?>
						<tr>
							<td colspan="4"><strong>BLOCK: <?=$wbv['block'];?></strong></td>
						</tr>
						<?if($wbv['sections']):?>
							<?foreach($wbv['sections'] as $sec):
								$male[] = $sec['male'];
								$female[] = $sec['female'];
							?>
								<tr>
									<td><a href="<?=site_url('master_list/#'.$sec['id']);?>" url="<?=site_url('output/ajax_fetch_students/'.$sec['id']);?>" class="show-students"><?=ucwords(strtolower($sec['sectionname']));?></a></td>
									<td><i class="icon-g-user"></i><span class="badge badge-info"><?=$sec['male'];?></span></td>
									<td><i class="icon-g-girl"></i><span class="badge badge-success"><?=$sec['female'];?></span></td>
									<td><i class="icon-g-group"></i><span class="badge badge-inverse"><?=$sec['total'];?></span></td>
								</tr>
							<?endforeach;?>
						<?else:?>
							<tr>
								<td><i>No Section Assigned to this block.</i></td>
								<td><i class="icon-g-user"></i><span class="badge badge-info">0</span></td>
								<td><i class="icon-g-girl"></i><span class="badge badge-success">0</span></td>
								<td><i class="icon-g-group"></i><span class="badge badge-inverse">0</span></td>
							</tr>
						<?endif;?>
				<?endforeach;?>
			<?	//without blocks
				elseif($sv['block_data']):?>
					<tr>
						<td colspan="4"><i>Not Assigned To Block.</i></td>
					</tr>
					<?foreach ($sv['block_data'] as $wobk => $wobv):
						$male[] = $wobv['male'];
						$female[] = $wobv['female'];
					?>
						<tr>
							<td><a href="<?=site_url('master_list/#'.$wobv['id']);?>" url="<?=site_url('output/ajax_fetch_students/'.$wobv['id']);?>" class="show-students"><?=ucwords(strtolower($wobv['section']));?></a></td>
							<td><i class="icon-g-user"></i><span class="badge badge-info"><?=$wobv['male'];?></span></td>
							<td><i class="icon-g-girl"></i><span class="badge badge-success"><?=$wobv['female'];?></span></td>
							<td><i class="icon-g-group"></i><span class="badge badge-inverse"><?=$wobv['total'];?></span></td>
						</tr>
					<?endforeach;?>
			<?endif;?>
		<?endforeach;?>
		<tr class="success">
			<td><strong>Total</strong></td>
			<td><i class="icon-g-user"></i><span class="badge badge-info"><?=array_sum($male)?></span></td>
			<td><i class="icon-g-girl"></i><span class="badge badge-success"><?=array_sum($female);?></span></td>
			<td><i class="icon-g-group"></i><span class="badge badge-inverse"><?=array_sum($male) + array_sum($female)?></span></td>
		</tr>
	</table>
<?else:?>

<?endif;?>

<script>
$(document).ready(function() { 
    $('.show-students').click(function(e) { 
    	e.preventDefault();    
    	var url = $(this).attr('url');
    	var section_name = $(this).text();
		$.blockUI({ 
			css: {
				border: 'none', 
				padding: '15px', 
				backgroundColor: '#000', 
				'-webkit-border-radius': '10px', 
				'-moz-border-radius': '10px', 
				opacity: .5, 
				color: '#fff' 
			},
			message: 'fetching Students, Please Wait'
		});
        	
		$.ajax({ 
            url: url,
            type:"POST",
            cache: false
         }).done(function(output){
         	$.blockUI({
				theme:true,
				title:' ',
				message: output
			});

         	$('div.blockUI.blockMsg.ui-dialog').css('width','90%')
         									   .css('height','90%')
         									   .css('left','5%')
         									   .css('right','5%')
         									   .css('top','5%');
        	$('div.ui-widget-header.blockTitle').append().html('<button class="btn btn-mini btn-danger" id="close">Close</button> List Of Students: '+ section_name);
        	$('div.ui-widget-content.ui-dialog-content').css('max-height','90%');
			$('.blockOverlay').attr('title','Click Anywhere to close').click($.unblockUI);
			$('#close').click($.unblockUI);
         }).fail(function(){
         	$.unblockUI();
         	$( '#msgDialog > p' ).text( 'ERROR!' );
			$('.ui-dialog-buttonpane').find('button').remove();
			$( '#msgDialog > div.content' ).text('Sorry But System was Unable to fetch students for this section.');
			$("#msgDialog").dialog("open");
         }); 
    }); 
}); 
</script>